package com.briup.day06;

import sun.applet.Main;

import java.util.Scanner;

/**
 * @author ThinkBook
 */
public class Test02_While {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("input two num:");
        int x = scanner.nextInt();
        int y = scanner.nextInt();
//        比大小
        int max = (x>y) ? x : y;
        int min = (x<y) ? x : y;
        if (max % min ==0){
            System.out.println("最大公约数："+min);
            System.out.println("最小公倍数："+max);
            return;
        }
//        辗转相除
        int yu = max % min;
        while (yu != 0){
            max = min;
            min = yu;
            yu = max%min;
        }
        System.out.println("最大公约数: " + min);
        System.out.println("最小公倍数: " + x*y/min);
    }
    public static void main03(String[] args) {
        int count = 0;
        double size = 0.1;
        while (size <=8844430){
            size *=2;
            count++;
        }
        System.out.println(size);
        System.out.println("需要折叠"+count+"次");
    }
    public static void main02(String[] args) {
        int i =1;
        int sum = 0;
        while (i<100){
            if(i%2!=0){
            sum +=i;
            }
            i++;
        }
        System.out.println("1-100的奇数和为："+sum);
    }
//    使用while循环输入所有的水仙花数
//    封装一个方法，用来判断传入的整数是否是水仙花数
    public static void main01(String[] args) {
        int i = 100;
        while(i<1000){
            if(isFlowerNum(i)){
                System.out.println(i+"是水仙花数");
            }
            i++;
        }
    }
    public static boolean isFlowerNum(int num) {

            // 获取个十百位上的数值
            // 256 ==>  个位  i % 10
            //          十位  i / 10 % 10
            //          百位  i / 100
            int g = num % 10;
            int s = num / 10 % 10;
            int b = num / 100;

            //判断i是否为水仙花数
            if (num == g * g * g + s * s * s + b * b * b) {
                return true;
            }
            return false;
        }
}
